Skip to main content

How to make const [a, b] = {a:1, b:2}

Object.prototype[Symbol.iterator] = function () {
return Object.values(this)[Symbol.iterator]();
};

How to make "instance" instanceof demo

class demo {
static [Symbol.hasInstance](item) {
return item === "instance";
}
}
"instance" instanceof demo; // true

With node.js, you can actually decide what to show on console.log

nodejs.org

const password = {
toString() {
return "xxxxxxxx";
},
[Symbol.for("nodejs.util.inspect.custom")](depth, inspectOptions, inspect) {
return `Password <${this.toString()}>`;
},
};
console.log(password);
// Prints Password <xxxxxxxx>